home *** CD-ROM | disk | FTP | other *** search
- unit frm2;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls;
-
- type
- TFormDialog = class(TForm)
- procedure FormCreate(Sender: TObject);
- procedure btnAddClick(Sender: TObject);
- private
- Edit1: TEdit;
- ListItems: TListBox;
- btnAdd: TButton;
- function GetItems(Index: Integer): string;
- procedure SetItems(Index: Integer; const Value: string);
- protected
- function GetText: String; virtual;
- procedure SetText(const Value: String); virtual;
- public
- constructor Create (Text: string); reintroduce; overload;
- property Text: String
- read GetText write SetText;
- property Items [Index: Integer]: string
- read GetItems write SetItems; default;
- end;
-
- implementation
-
- {$R *.DFM}
-
- { TForm2 }
-
- constructor TFormDialog.Create(Text: string);
- begin
- inherited Create (Application);
- Edit1.Text := Text;
- end;
-
- function TFormDialog.GetText: String;
- begin
- Result := Edit1.Text;
- end;
-
- procedure TFormDialog.SetText(const Value: String);
- begin
- Edit1.Text := Value;
- end;
-
- procedure TFormDialog.FormCreate(Sender: TObject);
- begin
- Edit1 := FindComponent ('Edit1') as TEdit;
- ListItems := FindComponent ('ListItems') as TListBox;
- btnAdd := FindComponent ('btnAdd') as TButton;
- end;
-
- function TFormDialog.GetItems(Index: Integer): string;
- begin
- if Index >= ListItems.Items.Count then
- raise Exception.Create ('TFormDialog: Out of Range');
- Result := ListItems.Items [Index];
- end;
-
- procedure TFormDialog.SetItems(Index: Integer; const Value: string);
- begin
- if Index >= ListItems.Items.Count then
- raise Exception.Create ('TFormDialog: Out of Range');
- ListItems.Items [Index] := Value;
- end;
-
- procedure TFormDialog.btnAddClick(Sender: TObject);
- begin
- ListItems.Items.Add (Edit1.Text);
- end;
-
- initialization
- RegisterClasses ([TEdit,
- TListBox,
- TButton]);
- end.
-